package com.stefan.stack;

public interface StefanStack<E> {
    void push(E e);
    E pop();
    int size();
    boolean isEmpty();

    //对称元素匹配 例如： {{{[[[((()))]]]}}}
    default boolean charsMatcher(String s) {
        StefanStack<Character> stack = new ArrayStefanStack<>(20);
        char[] charArray = s.toCharArray();
        Character pop = null;
        for (char c : charArray) {
            switch (c) {
                case '{':
                case '[':
                case '(':
                    stack.push(c);
                    break;
                case '}':
                    pop = stack.pop();
                    if (pop =='{') {
                        break;
                    } else {
                        return false;
                    }
                case ']':
                    pop = stack.pop();
                    if (pop =='[') {
                        break;
                    } else {
                        return false;
                    }
                case ')':
                    pop = stack.pop();
                    if (pop =='(') {
                        break;
                    } else {
                        return false;
                    }
            }
        }
        return stack.isEmpty();
    }
}
